<!DOCTYPE html>
<html>

<head>
    <title><?php echo $pageTitle; ?></title>
    <link rel="stylesheet" href="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/css/bootstrap.min.css">
    <style>
        .navbar-brand {
            font-size: 24px;
        }

        .nav-link {
            font-size: 18px;
        }

        .nav-item {
            margin-right: 10px;
        }

        .logout-link {
            margin: auto;
            font-size: 14px;
            color: white;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .admin-link {
            font-size: 18px;
            margin-right: 10px;
        }

        .navbar {
            margin-bottom: 20px;
        }

        .collapse {
            justify-content: flex-end;
        }
    </style>
</head>

<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="#">星 · StarLearning</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ml-auto">
                    <?php if (isset($_COOKIE['user_id'])) : ?>
                        <li class="nav-item <?php echo ($currentPage == 'index') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/main/index.php">首页</a>
                        </li>
                        <li class="nav-item <?php echo ($currentPage == 'rank') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/main/rank.php">排行榜</a>
                        </li>
                        <li class="nav-item <?php echo ($currentPage == 'upload') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/user/upload.php">上传卡片</a>
                        </li>
                        <li class="nav-item <?php echo ($currentPage == 'center') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/user/center.php">个人中心</a>
                        </li>
                        <li class="nav-item <?php echo ($currentPage == 'feedback') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/user/feedback.php">提交反馈</a>
                        </li>
                        <?php if (isset($_COOKIE['role']) && $_COOKIE['role'] === 'admin') : ?>
                            <li class="nav-item admin-link">
                                <a class="nav-link" href="./star/admin/manage-user.php">管理用户</a>
                            </li>
                            <li class="nav-item admin-link">
                                <a class="nav-link" href="./star/admin/manage-cards.php">管理卡片</a>
                            </li>
                            <li class="nav-item admin-link">
                                <a class="nav-link" href="./star/admin/manage-feedback.php">用户反馈</a>
                            </li>
                        <?php endif; ?>
                        <span class="logout-link">
                            <?php
                            if (isset($_COOKIE['role'])) {
                                switch ($_COOKIE['role']) {
                                    case 'admin':
                                        echo '欢迎，' . $_COOKIE['username'] . ' 管理员';
                                        break;
                                    case 'user':
                                        echo '欢迎，' . $_COOKIE['username'] . ' 用户';
                                        break;
                                    default:
                                        echo '欢迎，' . $_COOKIE['username'] . ' 访客';
                                        break;
                                }
                                echo "<br><a href='../main/logout.php'>退出登录</a>";
                            } else {
                                echo '欢迎，访客';
                            }
                            ?>
                        </span>
                    <?php else : ?>
                        <li class="nav-item <?php echo ($currentPage == 'index') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/main/index.php">首页</a>
                        </li>
                        <li class="nav-item <?php echo ($currentPage == 'rank') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/main/rank.php">排行榜</a>
                        </li>
                        <!-- <li class="nav-item <?php echo ($currentPage == 'login') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/main/login.php">登录</a>
                        </li>
                        <li class="nav-item <?php echo ($currentPage == 'register') ? 'active' : ''; ?>">
                            <a class="nav-link" href="./star/main/register.php">注册</a>
                        </li> -->
                    <?php endif; ?>
                </ul>
            </div>
        </div>
    </nav>
</body>

</html>